﻿/*
    Copyright (C) 2012  Milton da Silva Junior - admin.jr.dotnet@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Loja.Controllers
{
    public class LoginController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LogOn()
        {
            return RedirectToAction("Index");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult LogOn(string usuario, string senha, bool? manter)
        {
            usuario = "teste";
            senha = "1234567890";
            manter = true;

            usuario = usuario.ToLower();
            if (Membership.ValidateUser(usuario, senha))
            {
                FormsAuthentication.SetAuthCookie(usuario, (bool)manter);
                return RedirectToAction("Index", "Home");
            }
            ModelState.AddModelError("geral", "Usuário ou senha inválidos");
            return View();
        }
        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Index", "Home");
        }
    }
}
